package com.yc.web.controllers;

import com.yc.domain.Account;
import com.yc.service.BankBiz;
import com.yc.service.BankBizImpl;
import com.yc.web.model.JsonModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zwei
 * @create 2024-08-22 16:25
 */
@RestController
@RequestMapping("/bank")
public class BankController {
    @Autowired
    private BankBiz bankBiz;
    @RequestMapping(value = "/deposite",method = {RequestMethod.POST,RequestMethod.GET})
    public JsonModel deposit(Integer accountid,double money) {
        Account a = bankBiz.deposite(accountid, money);
        JsonModel jsonModel = new JsonModel();
        jsonModel.setCode(1);
        jsonModel.setObj(a);
        return jsonModel;
    }
    @RequestMapping(value = "/withdraw",method = {RequestMethod.POST,RequestMethod.GET})
    public JsonModel withdraw(Integer accountid,double money) {
        Account a = bankBiz.withdraw(accountid, money);
        JsonModel jsonModel = new JsonModel();
        jsonModel.setCode(1);
        jsonModel.setObj(a);
        return jsonModel;
    }
    @RequestMapping(value = "/transfer",method = {RequestMethod.POST,RequestMethod.GET})
    public JsonModel transfer(Integer accountid,double money,Integer toaccountid) {
        Account a = bankBiz.transfer(accountid, money,toaccountid);
        JsonModel jsonModel = new JsonModel();
        jsonModel.setCode(1);
        jsonModel.setObj(a);
        return jsonModel;
    }
    @RequestMapping(value = "/findAccount",method = {RequestMethod.POST,RequestMethod.GET})
    public JsonModel findAccount(Integer accountid) {
        Account a = bankBiz.findAccount(accountid);
        JsonModel jsonModel = new JsonModel();
        jsonModel.setCode(1);
        jsonModel.setObj(a);
        return jsonModel;
    }
    @RequestMapping(value = "/openAccount",method = {RequestMethod.POST,RequestMethod.GET})
    public JsonModel openAccount(double money) {
        Account a = bankBiz.openAccount(money);
        JsonModel jsonModel = new JsonModel();
        jsonModel.setCode(1);
        jsonModel.setObj(a);
        return jsonModel;
    }
}
